//
//  SJZArrowAndLabelView.m
//  SJZMetro
//
//  Created by 彭利民 on 2017/6/30.
//  Copyright © 2017年 bwton. All rights reserved.
//

#import "SJZArrowAndLabelView.h"
@interface SJZArrowAndLabelView()

@property (nonatomic, strong) UILabel *rightLabel;
@property (nonatomic, strong) UIImageView *image;
@end
@implementation SJZArrowAndLabelView

- (id)initWithFrame:(CGRect)frame{
    self  = [super initWithFrame:frame];
    if(self) {
//        self.titleLabel.font = [UIFont systemFontOfSize:11];
#warning PLM 这个图片还没有 加
        
        UILabel *rightLabel = [[UILabel alloc] init];
        rightLabel.textColor = [UIColor lightGrayColor];
        rightLabel.font = [UIFont systemFontOfSize:13];
        self.rightLabel = rightLabel;
        
        [self addSubview:rightLabel];
        
        UIImageView *image =
        [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_arrow"]];
        self.image = image;
        [self addSubview:image];
    }
    return self;
}


- (void)setBadgeValue:(NSString *)badgeValue {
    _badgeValue = [badgeValue copy];
    
    
    // 根据文字计算尺寸
    self.rightLabel.text = badgeValue;
    self.rightLabel.y = -8;
    self.rightLabel.height = self.height;
    self.rightLabel.x = -5;
//    self.rightLabel.y = 0;
    
    self.rightLabel.size = [badgeValue sizeWithFont:self.rightLabel.font maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
    self.width = self.rightLabel.size.width + self.image.width;
    self.image.x = self.rightLabel.width+ self.rightLabel.x + 5;
    self.image.y = -5;
//    self.image.height = self.rightLabel.height;
//    [self setTitle:badgeValue forState:UIControlStateNormal];
    
//    CGSize titleSize = [badgeValue sizeWithFont:self.titleLabel.font maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
//    CGFloat bgW = self.currentBackgroundImage.size.width;
//    if (titleSize.width < bgW) {
//        self.width = bgW;
//    }else{
//        self.width = titleSize.width + 10;
//    }
}

@end
